package com.huzz.controller;

import cloud.tianai.captcha.spring.vo.CaptchaResponse;
import cloud.tianai.captcha.spring.vo.ImageCaptchaVO;
import cloud.tianai.captcha.validator.common.model.dto.ImageCaptchaTrack;
import cn.dev33.satoken.annotation.SaIgnore;
import com.huzz.service.CaptchaService;
import com.huzz.util.body.JsonResult;
import com.huzz.util.body.ResultTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Name 验证码
 * @Description 描述
 * @Author 童年的纸飞机
 * @Since 2023-06-2023/6/7 16:17
 */
@Api(tags = "系统验证码模块 API")
@SaIgnore
@RestController
@RequestMapping("/api/captcha")
public class CaptchaController {

    @Autowired
    private CaptchaService captchaService;

    @ApiOperation("生成验证码")
    @GetMapping("/generateCaptcha")
    public JsonResult<CaptchaResponse<ImageCaptchaVO>> generateCaptcha(@RequestParam(defaultValue = "SLIDER") String captchaType) {
        return ResultTool.success(captchaService.generateCaptcha(captchaType));
    }

    @ApiOperation("校验验证码")
    @PostMapping("/verifyCaptcha")
    public JsonResult<Boolean> verifyCaptcha(@RequestParam("id") String id, @RequestBody ImageCaptchaTrack imageCaptchaTrack) {
        return ResultTool.success(captchaService.verifyCaptcha(id, imageCaptchaTrack));
    }

}
